﻿// Decompiled with JetBrains decompiler
// Type: SP1.AtributeValueLibrary
// Assembly: SP1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4A78F1E7-7FD5-407C-8917-5F99ECC43C34
// Assembly location: C:\Users\KasimGulcan\Desktop\Project\DynaCAD\bin\Debug\SP1.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shapes;

namespace SP1
{
  public static class AtributeValueLibrary
  {
    public static Brush GetBrush(string s)
    {
      if (s.Contains("url"))
      {
        for (int index = 0; index < DefinitionElement.GEL.Count; ++index)
        {
          if (s.Replace("url(#", "").Replace(")", "").Contains(DefinitionElement.GEL[index].Name))
            return (Brush) DefinitionElement.GEL[index].GB;
        }
        Console.WriteLine("Renk Değeri Bulunmadı:" + s);
        return (Brush) null;
      }
      if (s.Contains("grey"))
        s = s.Replace("grey", "gray");
      try
      {
        if (s.Contains("rgb"))
        {
          s = s.Replace("rgb", "");
          s = s.Replace("(", "");
          s = s.Replace(")", "");
          if (s.Contains(","))
            s = s.Replace(" ", "");
          string[] strArray = s.Split(new char[2]
          {
            ',',
            ' '
          });
          if (strArray.Length == 3)
          {
            SolidColorBrush solidColorBrush = new SolidColorBrush();
            if (!Enumerable.Contains<char>((IEnumerable<char>) s, '%'))
            {
              solidColorBrush.Color = Color.FromArgb(byte.MaxValue, Convert.ToByte(strArray[0]), Convert.ToByte(strArray[1]), Convert.ToByte(strArray[2]));
              return (Brush) solidColorBrush;
            }
            solidColorBrush.Color = Color.FromArgb(byte.MaxValue, Convert.ToByte(Convert.ToDouble(strArray[0].Replace("%", "")) * (double) byte.MaxValue / 100.0), Convert.ToByte(Convert.ToDouble(strArray[1].Replace("%", "")) * (double) byte.MaxValue / 100.0), Convert.ToByte(Convert.ToDouble(strArray[2].Replace("%", "")) * (double) byte.MaxValue / 100.0));
            return (Brush) solidColorBrush;
          }
        }
        return (Brush) new BrushConverter().ConvertFromString(s);
      }
      catch
      {
        Console.WriteLine("Renk Değeri Bulunmadı:" + s);
      }
      return (Brush) null;
    }

    public static PenLineCap LineCapConvertor(string s)
    {
      switch (s.Replace(" ", ""))
      {
        case "butt":
          return PenLineCap.Flat;
        case "square":
          return PenLineCap.Square;
        case "round":
          return PenLineCap.Round;
        default:
          Console.WriteLine("Bilinmeyen LineCap Değeri:" + s);
          return PenLineCap.Flat;
      }
    }

    public static PenLineJoin LineJoinConvertor(string s)
    {
      switch (s)
      {
        case "miter":
          return PenLineJoin.Miter;
        case "bevel":
          return PenLineJoin.Bevel;
        case "round":
          return PenLineJoin.Round;
        default:
          Console.WriteLine("Bilinmeyen LineJoin Değeri:" + s);
          return PenLineJoin.Miter;
      }
    }

    public static FillRule FillRuleConvertor(string s)
    {
      switch (s)
      {
        case "evenodd":
          return FillRule.EvenOdd;
        case "nonzero":
          return FillRule.Nonzero;
        default:
          Console.WriteLine("Bilinmeyen FillRule Property:" + s);
          return FillRule.Nonzero;
      }
    }

    public static PointCollection PointCollectionConvertor(string s)
    {
      string[] strArray1 = s.Split(' ');
      PointCollection pointCollection = new PointCollection();
      foreach (string str in strArray1)
      {
        char[] chArray = new char[1]
        {
          ','
        };
        string[] strArray2 = str.Split(chArray);
        Point point = new Point();
        if (strArray2.Length == 2)
        {
          point.X = AtributeValueLibrary.DoubleConvertor(strArray2[0]);
          point.Y = AtributeValueLibrary.DoubleConvertor(strArray2[1]);
          pointCollection.Add(point);
        }
        else
          Console.WriteLine("Point Collection Oluşturulamadı:" + s);
      }
      return pointCollection;
    }

    public static DoubleCollection StrokeDashArrayConvertor(string s)
    {
      DoubleCollection doubleCollection = new DoubleCollection();
      string str = s;
      char[] chArray = new char[1]
      {
        ','
      };
      foreach (string s1 in str.Split(chArray))
      {
        try
        {
          doubleCollection.Add(AtributeValueLibrary.DoubleConvertor(s1));
        }
        catch
        {
          Console.WriteLine("Bilinmeyen StrokeDashArray Değeri:" + s);
          doubleCollection.Add(2.0);
          doubleCollection.Add(2.0);
        }
      }
      return doubleCollection;
    }

    public static Effect FilterConvertor(string s)
    {
      for (int index = 0; index < DefinitionElement.FEL.Count; ++index)
      {
        if (s.Contains(DefinitionElement.FEL[index].Name))
          return DefinitionElement.FEL[index].E;
      }
      Console.WriteLine("FilterElement Bulunmadı:" + s);
      return (Effect) null;
    }

    public static void StyleAttribute(ref TextBlock x, ref Border B, string s2)
    {
      FontFamilyConverter fontFamilyConverter = new FontFamilyConverter();
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", ""))
          {
            case "stroke":
              B.BorderBrush = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Foreground = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "text-anchor":
              x.TextAlignment = AtributeValueLibrary.TextAlighmentConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            case "letter-spacing":
              x.FontFamily.LineSpacing = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "kerning":
              x.FontFamily.LineSpacing = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "transform":
              TransFormLibrary.TransForm((UIElement) B, strArray[1]);
              continue;
            case "font-family":
              try
              {
                x.FontFamily = (FontFamily) fontFamilyConverter.ConvertFromString(strArray[1]);
                continue;
              }
              catch
              {
                Console.WriteLine("FontFamily Could not be Converted" + strArray[1]);
                continue;
              }
            default:
              continue;
          }
        }
      }
    }

    public static Line StyleAttribute(Line x, string s2, out double StrokeOpacity, out double FillOpacity)
    {
      StrokeOpacity = 1.0;
      FillOpacity = 1.0;
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", ""))
          {
            case "stroke":
              x.Stroke = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Fill = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "stroke-miterlimit":
              x.StrokeMiterLimit = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-dasharray":
              x.StrokeDashArray = AtributeValueLibrary.StrokeDashArrayConvertor(strArray[1]);
              continue;
            case "stroke-width":
              x.StrokeThickness = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-linecap":
              x.StrokeEndLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              x.StrokeStartLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              continue;
            case "stroke-opacity":
              StrokeOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-opacity":
              FillOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "opacity":
              x.Opacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            default:
              continue;
          }
        }
      }
      return x;
    }

    public static Ellipse StyleAttribute(Ellipse x, string s2, out double StrokeOpacity, out double FillOpacity)
    {
      StrokeOpacity = 1.0;
      FillOpacity = 1.0;
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", ""))
          {
            case "stroke":
              x.Stroke = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Fill = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "stroke-miterlimit":
              x.StrokeMiterLimit = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-dasharray":
              x.StrokeDashArray = AtributeValueLibrary.StrokeDashArrayConvertor(strArray[1]);
              continue;
            case "stroke-width":
              x.StrokeThickness = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-linecap":
              x.StrokeEndLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              x.StrokeStartLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              continue;
            case "stroke-opacity":
              StrokeOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-opacity":
              FillOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "opacity":
              x.Opacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            default:
              continue;
          }
        }
      }
      return x;
    }

    public static Path StyleAttribute(Path x, string s2, out double StrokeOpacity, out double FillOpacity)
    {
      StrokeOpacity = 1.0;
      FillOpacity = 1.0;
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", ""))
          {
            case "stroke":
              x.Stroke = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Fill = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "stroke-miterlimit":
              x.StrokeMiterLimit = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-dasharray":
              x.StrokeDashArray = AtributeValueLibrary.StrokeDashArrayConvertor(strArray[1]);
              continue;
            case "stroke-width":
              x.StrokeThickness = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-linecap":
              x.StrokeEndLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              x.StrokeStartLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              continue;
            case "stroke-opacity":
              StrokeOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-opacity":
              FillOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "opacity":
              x.Opacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            default:
              continue;
          }
        }
      }
      return x;
    }

    public static Polygon StyleAttribute(Polygon x, string s2, out double StrokeOpacity, out double FillOpacity)
    {
      StrokeOpacity = 1.0;
      FillOpacity = 1.0;
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", ""))
          {
            case "stroke":
              x.Stroke = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Fill = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "stroke-miterlimit":
              x.StrokeMiterLimit = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-dasharray":
              x.StrokeDashArray = AtributeValueLibrary.StrokeDashArrayConvertor(strArray[1]);
              continue;
            case "stroke-width":
              x.StrokeThickness = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-linecap":
              x.StrokeEndLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              x.StrokeStartLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              continue;
            case "stroke-opacity":
              StrokeOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-opacity":
              FillOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "opacity":
              x.Opacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-rule":
              x.FillRule = AtributeValueLibrary.FillRuleConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            default:
              continue;
          }
        }
      }
      return x;
    }

    public static Polyline StyleAttribute(Polyline x, string s2, out double StrokeOpacity, out double FillOpacity)
    {
      StrokeOpacity = 1.0;
      FillOpacity = 1.0;
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", ""))
          {
            case "stroke":
              x.Stroke = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Fill = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "stroke-miterlimit":
              x.StrokeMiterLimit = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-dasharray":
              x.StrokeDashArray = AtributeValueLibrary.StrokeDashArrayConvertor(strArray[1]);
              continue;
            case "stroke-width":
              x.StrokeThickness = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-linecap":
              x.StrokeEndLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              x.StrokeStartLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              continue;
            case "stroke-opacity":
              StrokeOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-opacity":
              FillOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "opacity":
              x.Opacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-rule":
              x.FillRule = AtributeValueLibrary.FillRuleConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            default:
              continue;
          }
        }
      }
      return x;
    }

    public static Rectangle StyleAttribute(Rectangle x, string s2, out double StrokeOpacity, out double FillOpacity)
    {
      StrokeOpacity = 1.0;
      FillOpacity = 1.0;
      string str1 = s2;
      char[] chArray1 = new char[1]
      {
        ';'
      };
      foreach (string str2 in str1.Split(chArray1))
      {
        char[] chArray2 = new char[1]
        {
          ':'
        };
        string[] strArray = str2.Split(chArray2);
        if (strArray.Length == 2 && strArray[1].Replace(" ", "") != "none")
        {
          switch (strArray[0].Replace(" ", "").Replace("\n", ""))
          {
            case "stroke":
              x.Stroke = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "fill":
              x.Fill = AtributeValueLibrary.GetBrush(strArray[1]);
              continue;
            case "stroke-miterlimit":
              x.StrokeMiterLimit = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-dasharray":
              x.StrokeDashArray = AtributeValueLibrary.StrokeDashArrayConvertor(strArray[1]);
              continue;
            case "stroke-width":
              x.StrokeThickness = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "stroke-linecap":
              x.StrokeEndLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              x.StrokeStartLineCap = AtributeValueLibrary.LineCapConvertor(strArray[1]);
              continue;
            case "stroke-opacity":
              StrokeOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "fill-opacity":
              FillOpacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "opacity":
              x.Opacity = AtributeValueLibrary.DoubleConvertor(strArray[1]);
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(strArray[1]);
              continue;
            default:
              continue;
          }
        }
      }
      return x;
    }

    public static double DoubleConvertor(string s)
    {
      try
      {
        return Convert.ToDouble(s.Replace(".", ","));
      }
      catch
      {
        try
        {
          if (s.Contains("px"))
            return Convert.ToDouble(s.Remove(s.Length - 2).Replace(".", ","));
          if (s.Contains("pt"))
            return 96.0 * (Convert.ToDouble(s.Remove(s.Length - 2).Replace(".", ",")) / 72.0);
          if (s.Contains("pc"))
            return 16.0 * Convert.ToDouble(s.Remove(s.Length - 2).Replace(".", ","));
          if (s.Contains("cm"))
            return 960.0 * (Convert.ToDouble(s.Remove(s.Length - 2).Replace(".", ",")) / 25.4);
          if (s.Contains("mm"))
            return 96.0 * (Convert.ToDouble(s.Remove(s.Length - 2).Replace(".", ",")) / 25.4);
          if (s.Contains("in"))
            return 96.0 * Convert.ToDouble(s.Remove(s.Length - 2).Replace(".", ","));
        }
        catch
        {
          Console.WriteLine("Unknown Atribute Value:" + s + "the value has been set as 100px");
          return 100.0;
        }
        Console.WriteLine("Unknown Unit:" + s + ":the value has been set as 100px");
        return 100.0;
      }
    }

    public static GradientSpreadMethod SpreadMethodConvertor(string s)
    {
      GradientSpreadMethod gradientSpreadMethod = GradientSpreadMethod.Pad;
      switch (s)
      {
        case "pad":
          gradientSpreadMethod = GradientSpreadMethod.Pad;
          break;
        case "reflect":
          gradientSpreadMethod = GradientSpreadMethod.Reflect;
          break;
        case "repeat":
          gradientSpreadMethod = GradientSpreadMethod.Repeat;
          break;
      }
      return gradientSpreadMethod;
    }

    public static BrushMappingMode MappingModeConvertor(string s)
    {
      return !(s == "userSpaceOnUse") ? BrushMappingMode.RelativeToBoundingBox : BrushMappingMode.Absolute;
    }

    public static TextAlignment TextAlighmentConvertor(string s)
    {
      if (s.Contains("start"))
        return TextAlignment.Left;
      if (s.Contains("middle"))
        return TextAlignment.Center;
      if (s.Contains("end"))
        return TextAlignment.Right;
      Console.WriteLine("TextAlighment Çevrim Başarısız:" + s);
      return TextAlignment.Left;
    }
  }
}
